﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Globalization;

namespace DAO
{
    public class HoaDonDAO
    {
        public static HoaDon timhd()
        {
            try
            {
                QLSTLinqDataContext rv = new QLSTLinqDataContext();
                var cust =
    (from c in rv.HoaDons.OrderByDescending(x => x.Id)     
     select c).First();

                return cust;
            }
            catch
            {
                return null;
            }
        }

        public static bool Them(HoaDon aCT)
        {
            try
            {
                QLSTLinqDataContext rv = new QLSTLinqDataContext();
                rv.HoaDons.InsertOnSubmit(aCT);
                rv.SubmitChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static List<thongkengayResult> LayDSTheoNgay(DateTime d)
        {
            try
            {
                
                QLSTLinqDataContext rv = new QLSTLinqDataContext();


                List<thongkengayResult> temp = new List<thongkengayResult>();
                var query = rv.thongkengay(d);


                temp = query.ToList();
                return temp;
            }
            catch
            {
                return null;
            }
            
        }
    }
}
